package com.loong.user.controller.backend;

import com.loong.common.domain.BaseQuery;
import com.loong.common.mvc.BaseBackendController;
import com.loong.common.rest.Result;
import com.loong.common.validator.group.CommonInsert;
import com.loong.common.validator.group.CommonUpdate;
import com.loong.common.validator.group.CommonValidate;
import com.loong.user.common.backend.param.ManageRoleParam;
import com.loong.user.common.backend.param.ManageRoleQueryParam;
import com.loong.user.handler.ManageRoleHandler;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 系统角色管理控制器
 * @Author: hzp
 * @Date: 2020-10-16 17:15
 */
@RestController
@RequestMapping("/manage/user/systemRole")
public class ManageRoleController extends BaseBackendController {
    @Resource
    private ManageRoleHandler manageRoleHandler;

    /**
     * @description: 保存后台系统角色
     * @param param
     * @return
     *
     */
    @PostMapping("save")
    public Result save(@Validated(value = {CommonInsert.class, CommonValidate.class}) ManageRoleParam param){
        param.setId(null);
        return   handlerExecutor.execute(()->manageRoleHandler.save(param));
    }

    /**
     * @description: 更新后台系统角色
     * @param param
     * @return
     */
    @PostMapping("update")
    public Result update(@Validated(value = {CommonUpdate.class, CommonValidate.class}) ManageRoleParam param){
        return  handlerExecutor.execute(()->manageRoleHandler.update(param));
    }


    /**
     *
     *  @description: 获取系统角色树
     * @return
     */
    @PostMapping("queryTree")
    public Result queryAllResourceTree(){
        return  handlerExecutor.execute(()->manageRoleHandler.queryAllRoleTree());
    }

    /**
     *根据id删除后台角色
     * @param roleIds
     */
    @PostMapping("delete")
    public Result deleteById(@RequestParam("roleIds") List<Long> roleIds){

        return handlerExecutor.execute(()->manageRoleHandler.deleteById(roleIds));
    }

    /**
     * 根据部门id查询所有角色
     * @param deptId
     * @return
     */
    @PostMapping("queryRoleByDeptId")
    public Result queryRoleByDeptId(Long deptId){
        return handlerExecutor.execute(()->manageRoleHandler.queryRoleByDeptId(deptId));
    }

    /**
     * 分页查询
     * @param baseQuery
     * @param param
     * @return
     */
    @PostMapping("pageQuery")
    public Result pageQuery(BaseQuery baseQuery, ManageRoleQueryParam param){
        return  handlerExecutor.execute(()->manageRoleHandler.pageQuery(baseQuery,param));
    }


}
